#ifndef __BSP_UART_H__
#define __BSP_UART_H__

#ifdef __cplusplus
 extern "C" {
#endif

#include "stdio.h"
#include "bsp_config.h"
#include "wl_version.h"

#if defined(WL_PROJECT_KIWI)            //TODO:
// #define ACU_COM_TEST_ENABLE

enum 
{
    UART_INDEX_DEBUG = 0,
#ifdef ACU_UART
    UART_INDEX_ACU,
#endif
#ifdef VCU_UART
    UART_INDEX_VCU,
#endif
#ifdef PAYLOAD_UART
    UART_INDEX_PAYLOAD,
#endif
    UART_INDEX_MAX,
};

typedef struct 
{
    UART_HandleTypeDef *puart;
    uint32_t msg_id;
    uint16_t ring_buf_id;
    uint16_t rx_buf_size;
    volatile uint16_t tx_buf_size;
    volatile uint16_t dma_read_index;
    uint8_t *rx_buf;
    uint8_t *tx_buf;
    uint8_t *rx_decode_buf;
    uint16_t rx_decode_end;
    uint16_t rx_decode_size;

    uint16_t tx_count;
    uint16_t rx_count;
    uint16_t rx_decode_count;
    uint16_t rx_on_decode;
    uint16_t rx_decode_loss;
    uint16_t rx_loss;
    uint16_t rx_decode;
    uint16_t err_cnt;
    uint16_t last_err_code;
}UartInfo_st;

extern UartInfo_st g_uart_info[UART_INDEX_MAX];

void uart_dbg_init(void);
void uart_com_init(void);
void uart_debug_handler(UartInfo_st *p_info,uint8_t is_irq);
void uart_common_handler(UartInfo_st *p_info,uint8_t is_irq);
void uart_tx_dma_stop(UartInfo_st *p_info);
void uart_dma_tx_start(UartInfo_st *p_info,uint8_t *buf,uint16_t len);
void print_uart_count(void);

#else
HAL_StatusTypeDef uart_tx_startDMA(UART_HandleTypeDef *huart, uint8_t* buf, uint16_t size);
void uart_rx_startDMA(UART_HandleTypeDef *huart, uint8_t* buf, uint8_t size);
#endif

#ifdef __cplusplus
}
#endif

#endif